package com.binance.zkconfig.app.property;

import com.binance.zkconfig.app.service.ZkConfig;
import org.springframework.core.env.EnumerablePropertySource;

import java.util.Set;


/**
 * Created by Fei.Huang on 2018/8/28.
 */
public class ZkConfigPropertySource extends EnumerablePropertySource<ZkConfig> {

    private static final String[] EMPTY_ARRAY = new String[0];

    public ZkConfigPropertySource(String context, ZkConfig source) {
        super(context, source);
    }

    @Override
    public Object getProperty(String name) {
        return this.source.getProperty(name);
    }

    @Override
    public String[] getPropertyNames() {
        Set<String> propertyNames = this.source.getPropertyNames();
        if (propertyNames.isEmpty()) {
            return EMPTY_ARRAY;
        }
        return propertyNames.toArray(new String[propertyNames.size()]);
    }
}
